<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="排序" prop="sortNum">
        <el-input
          v-model="queryParams.sortNum"
          placeholder="请输入排序"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作名称" prop="operationName">
        <el-input
          v-model="queryParams.operationName"
          placeholder="请输入操作名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作路径" prop="path">
        <el-input
          v-model="queryParams.path"
          placeholder="请输入操作路径"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务操作人id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入业务操作人id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前步骤" prop="currentStep">
        <el-input
          v-model="queryParams.currentStep"
          placeholder="请输入当前步骤"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="变更的参数json格式" prop="dataJson">
        <el-input
          v-model="queryParams.dataJson"
          placeholder="请输入变更的参数json格式"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目流程id" prop="itemFlowId">
        <el-input
          v-model="queryParams.itemFlowId"
          placeholder="请输入项目流程id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目步骤" prop="approvalSteps">
        <el-input
          v-model="queryParams.approvalSteps"
          placeholder="请输入项目步骤"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最终审核结果描述" prop="resultDesc">
        <el-input
          v-model="queryParams.resultDesc"
          placeholder="请输入最终审核结果描述"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乐观锁" prop="revision">
        <el-input
          v-model="queryParams.revision"
          placeholder="请输入乐观锁"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createdBy">
        <el-input
          v-model="queryParams.createdBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdTime">
        <el-date-picker clearable
          v-model="queryParams.createdTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新人" prop="updatedBy">
        <el-input
          v-model="queryParams.updatedBy"
          placeholder="请输入更新人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedTime">
        <el-date-picker clearable
          v-model="queryParams.updatedTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['house:bizoperation:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['house:bizoperation:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['house:bizoperation:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['house:bizoperation:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bizoperationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="排序" align="center" prop="sortNum" />
      <el-table-column label="操作名称" align="center" prop="operationName" />
      <el-table-column label="操作路径" align="center" prop="path" />
      <el-table-column label="业务操作人id" align="center" prop="userId" />
      <el-table-column label="当前状态(0待审核 1审核中 2审核通过 3驳回 4撤回);当审核通过2 后，触发实际更新" align="center" prop="status" />
      <el-table-column label="当前步骤" align="center" prop="currentStep" />
      <el-table-column label="变更的参数json格式" align="center" prop="dataJson" />
      <el-table-column label="项目流程id" align="center" prop="itemFlowId" />
      <el-table-column label="项目步骤" align="center" prop="approvalSteps" />
      <el-table-column label="最终审核结果描述" align="center" prop="resultDesc" />
      <el-table-column label="乐观锁" align="center" prop="revision" />
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updatedBy" />
      <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['house:bizoperation:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['house:bizoperation:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改房源业务操作记录（流程实例，包含审批步骤（节点））;1、房源业务操作：新增房源、修改房源图片、上传视频、查看业主信息等操作，
2、如果需要审核，则在改变临时存储用户的修改，待审核通过后通过事件触发实际的修改，如果审核不通过，则根据实际状态修改状态
3、审核过程只有 待审核、审核中（如果需要多级审批，中间层级审核通过，就改成审核中，中间层级审核通过状态体现在步骤中、审核记录中）、通过、驳回、撤回状态。 通过、驳回、撤回状态是最终状态对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="bizoperationRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="排序" prop="sortNum">
          <el-input v-model="form.sortNum" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="操作名称" prop="operationName">
          <el-input v-model="form.operationName" placeholder="请输入操作名称" />
        </el-form-item>
        <el-form-item label="操作路径" prop="path">
          <el-input v-model="form.path" placeholder="请输入操作路径" />
        </el-form-item>
        <el-form-item label="业务操作人id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入业务操作人id" />
        </el-form-item>
        <el-form-item label="当前步骤" prop="currentStep">
          <el-input v-model="form.currentStep" placeholder="请输入当前步骤" />
        </el-form-item>
        <el-form-item label="变更的参数json格式" prop="dataJson">
          <el-input v-model="form.dataJson" placeholder="请输入变更的参数json格式" />
        </el-form-item>
        <el-form-item label="项目流程id" prop="itemFlowId">
          <el-input v-model="form.itemFlowId" placeholder="请输入项目流程id" />
        </el-form-item>
        <el-form-item label="项目步骤" prop="approvalSteps">
          <el-input v-model="form.approvalSteps" placeholder="请输入项目步骤" />
        </el-form-item>
        <el-form-item label="最终审核结果描述" prop="resultDesc">
          <el-input v-model="form.resultDesc" placeholder="请输入最终审核结果描述" />
        </el-form-item>
        <el-form-item label="乐观锁" prop="revision">
          <el-input v-model="form.revision" placeholder="请输入乐观锁" />
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="form.updatedBy" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedTime">
          <el-date-picker clearable
            v-model="form.updatedTime"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="0 表示未删除，1 表示已逻辑删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入0 表示未删除，1 表示已逻辑删除" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Bizoperation">
import { listBizoperation, getBizoperation, delBizoperation, addBizoperation, updateBizoperation } from "@/api/house/bizoperation"

const { proxy } = getCurrentInstance()

const bizoperationList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    sortNum: null,
    operationName: null,
    path: null,
    userId: null,
    status: null,
    currentStep: null,
    dataJson: null,
    itemFlowId: null,
    approvalSteps: null,
    resultDesc: null,
    revision: null,
    createdBy: null,
    createdTime: null,
    updatedBy: null,
    updatedTime: null,
  },
  rules: {
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询房源业务操作记录（流程实例，包含审批步骤（节点））;1、房源业务操作：新增房源、修改房源图片、上传视频、查看业主信息等操作，
2、如果需要审核，则在改变临时存储用户的修改，待审核通过后通过事件触发实际的修改，如果审核不通过，则根据实际状态修改状态
3、审核过程只有 待审核、审核中（如果需要多级审批，中间层级审核通过，就改成审核中，中间层级审核通过状态体现在步骤中、审核记录中）、通过、驳回、撤回状态。 通过、驳回、撤回状态是最终状态列表 */
function getList() {
  loading.value = true
  listBizoperation(queryParams.value).then(response => {
    bizoperationList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    sortNum: null,
    operationName: null,
    path: null,
    userId: null,
    status: null,
    currentStep: null,
    dataJson: null,
    itemFlowId: null,
    approvalSteps: null,
    resultDesc: null,
    revision: null,
    createdBy: null,
    createdTime: null,
    updatedBy: null,
    updatedTime: null,
    delFlag: null
  }
  proxy.resetForm("bizoperationRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加房源业务操作记录（流程实例，包含审批步骤（节点））;1、房源业务操作：新增房源、修改房源图片、上传视频、查看业主信息等操作，
2、如果需要审核，则在改变临时存储用户的修改，待审核通过后通过事件触发实际的修改，如果审核不通过，则根据实际状态修改状态
3、审核过程只有 待审核、审核中（如果需要多级审批，中间层级审核通过，就改成审核中，中间层级审核通过状态体现在步骤中、审核记录中）、通过、驳回、撤回状态。 通过、驳回、撤回状态是最终状态"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getBizoperation(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改房源业务操作记录（流程实例，包含审批步骤（节点））;1、房源业务操作：新增房源、修改房源图片、上传视频、查看业主信息等操作，
2、如果需要审核，则在改变临时存储用户的修改，待审核通过后通过事件触发实际的修改，如果审核不通过，则根据实际状态修改状态
3、审核过程只有 待审核、审核中（如果需要多级审批，中间层级审核通过，就改成审核中，中间层级审核通过状态体现在步骤中、审核记录中）、通过、驳回、撤回状态。 通过、驳回、撤回状态是最终状态"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["bizoperationRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateBizoperation(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addBizoperation(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除房源业务操作记录（流程实例，包含审批步骤（节点））;1、房源业务操作：新增房源、修改房源图片、上传视频、查看业主信息等操作，
2、如果需要审核，则在改变临时存储用户的修改，待审核通过后通过事件触发实际的修改，如果审核不通过，则根据实际状态修改状态
3、审核过程只有 待审核、审核中（如果需要多级审批，中间层级审核通过，就改成审核中，中间层级审核通过状态体现在步骤中、审核记录中）、通过、驳回、撤回状态。 通过、驳回、撤回状态是最终状态编号为"' + _ids + '"的数据项？').then(function() {
    return delBizoperation(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('house/bizoperation/export', {
    ...queryParams.value
  }, `bizoperation_${new Date().getTime()}.xlsx`)
}

getList()
</script>
